import { ref } from "vue";
import { useTodoStore } from "../stores/todo";

export function useTodoDelete() {
  const todoStore = useTodoStore();
  const showDeleteConfirm = ref(false);
  const todoToDelete = ref<string | null>(null);

  // 删除待办
  function deleteTodo(id: string) {
    todoToDelete.value = id;
    showDeleteConfirm.value = true;
  }

  // 确认删除
  function confirmDelete() {
    if (todoToDelete.value) {
      todoStore.deleteTodo(todoToDelete.value);
    }
    showDeleteConfirm.value = false;
    todoToDelete.value = null;
  }

  // 取消删除
  function cancelDelete() {
    showDeleteConfirm.value = false;
    todoToDelete.value = null;
  }

  return {
    showDeleteConfirm,
    todoToDelete,
    deleteTodo,
    confirmDelete,
    cancelDelete,
  };
}
